/**
 * 
 */
package com.kexinde.wjifen.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.kexinde.wjifen.model.NormalUser;
import com.kexinde.wjifen.service.INormalUserManager;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author vincent
 * 
 */
@Component("NormalUser")
@Scope("prototype")
public class NormalUserAction extends ActionSupport implements RequestAware,
		SessionAware {

	private NormalUser normalUser;
	private String validate;
	private INormalUserManager normalUserManager;
	private Map<String, Object> request;
	private Map<String, Object> session;

	public String showAll() {
		List<NormalUser> normalUsers = this.normalUserManager.showAll();
		request.put("normalUsers", normalUsers);
		return SUCCESS;
	}

	public String showOne() {
		this.normalUser = this.normalUserManager.showOne(normalUser
				.getUserName());
		request.put("normalUser", normalUser);
		return SUCCESS;
	}

	public String add() {
		if (this.normalUserManager.add(normalUser))
			return SUCCESS;
		else
			return ERROR;
	}

	public String delete() {
		if (this.normalUserManager.delete(normalUser))
			return SUCCESS;
		else
			return ERROR;
	}

	public String modify() {
		if (this.normalUserManager.modify(normalUser))
			return SUCCESS;
		else
			return ERROR;
	}

	public String login() {
		if (this.normalUserManager.login(validate, normalUser.getUserName(),
				normalUser.getPassword())) {
			session.put("normalUser", normalUser);
			return SUCCESS;
		} else
			return ERROR;
	}

	public String logout() {
		session.remove("normalUser");
		return SUCCESS;
	}

	public String exist() {
		return SUCCESS;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request = request;
	}

	public NormalUser getNormalUser() {
		return normalUser;
	}

	public void setNormalUser(NormalUser normalUser) {
		this.normalUser = normalUser;
	}

	public String getValidate() {
		return validate;
	}

	public void setValidate(String validate) {
		this.validate = validate;
	}

	public INormalUserManager getNormalUserManager() {
		return normalUserManager;
	}

	@Resource
	public void setNormalUserManager(INormalUserManager normalUserManager) {
		this.normalUserManager = normalUserManager;
	}

}
